Conversation
77fae4e to
4318162
Compare
- Check output when no argument is provided; - Check if stdin is ignored by default; - Check if stdin is ignored if file is provided; - Check how many arguments a utility accepts; - Check how word splitting works on multiple arguments; - Check if newline is present; and - How it treats the argument '-'.
0cc3cbe to
2e92192
Compare
ArrayBolt3
left a comment
There was a problem hiding this comment.
Tests pass both as-is and with the couple of functional changes suggested.
| i = 0 | ||
| self.tmpdir = tempfile.mkdtemp() | ||
| while i < 6: | ||
| self.tmpfiles_list.append(os.path.join(self.tmpdir, str(i))) | ||
| with open(self.tmpfiles_list[i], "w", encoding="utf-8") as file: | ||
| if i == 0: | ||
| file.write("") | ||
| elif i == 1: | ||
| file.write("".join(contents)) | ||
| elif i == 2: | ||
| file.write("".join(contents) + "\n") | ||
| elif i == 3: | ||
| file.write(self.text_dirty) | ||
| elif i in [4, 5]: | ||
| pass | ||
| file.flush() | ||
| file.close() | ||
| i += 1 |
There was a problem hiding this comment.
| i = 0 | |
| self.tmpdir = tempfile.mkdtemp() | |
| while i < 6: | |
| self.tmpfiles_list.append(os.path.join(self.tmpdir, str(i))) | |
| with open(self.tmpfiles_list[i], "w", encoding="utf-8") as file: | |
| if i == 0: | |
| file.write("") | |
| elif i == 1: | |
| file.write("".join(contents)) | |
| elif i == 2: | |
| file.write("".join(contents) + "\n") | |
| elif i == 3: | |
| file.write(self.text_dirty) | |
| elif i in [4, 5]: | |
| pass | |
| file.flush() | |
| file.close() | |
| i += 1 | |
| self.tmpdir = tempfile.mkdtemp() | |
| for i in range(0, 6): | |
| self.tmpfiles_list.append(os.path.join(self.tmpdir, str(i))) | |
| with open(self.tmpfiles_list[i], "w", encoding="utf-8") as file: | |
| if i == 0: | |
| file.write("") | |
| elif i == 1: | |
| file.write("".join(contents)) | |
| elif i == 2: | |
| file.write("".join(contents) + "\n") | |
| elif i == 3: | |
| file.write(self.text_dirty) | |
| elif i in [4, 5]: | |
| pass | |
| file.flush() | |
| file.close() |
There was a problem hiding this comment.
Github browser diff is bad on this case. Is the change while to for and removal of the individual i var assignments?
There was a problem hiding this comment.
Is the change while to for and removal of the individual i var assignments?
Yes.
Github browser diff is bad on this case.
Yeah... not sure why it didn't render this very well this time.
| shutil.rmtree(self.tmpdir) | ||
|
|
||
| def _del_module(self) -> None: | ||
| for module in ["stdisplay." + self.module]: # type: ignore # pylint: disable=no-member |
There was a problem hiding this comment.
It might be useful to document that self.module is going to be defined in the individual tests themselves.
| def _get_file(self, file: str) -> str: | ||
| """ | ||
| Helper function get contents of a file. | ||
| """ | ||
| with open(file, mode="r", encoding="utf-8") as fileobj: | ||
| text = fileobj.read() | ||
| return text |
There was a problem hiding this comment.
Could Path.read_text() be used instead of a custom helper function for this?
There was a problem hiding this comment.
Makes sense. Done.
| import stdisplay.tests | ||
|
|
||
|
|
||
| class TestSTCat(stdisplay.tests.TestSTBase): |
There was a problem hiding this comment.
| class TestSTCat(stdisplay.tests.TestSTBase): | |
| class TestSTCatn(stdisplay.tests.TestSTBase): |
| class TestSTPrint(stdisplay.tests.TestSTBase): | ||
| """ | ||
| Test stprint | ||
| Test stecho. |
There was a problem hiding this comment.
| Test stecho. | |
| Test stprint. |
| "", | ||
| self._get_file(file=self.tmpfiles["fill"]), | ||
| ) | ||
| # Empty stdin when writing to file and file sanitization. |
There was a problem hiding this comment.
| # Empty stdin when writing to file and file sanitization. | |
| # Empty stdout when writing to file and file sanitization. |
| self.text_dirty_sanitized, | ||
| self._get_file(file=self.tmpfiles["fill"]), | ||
| ) | ||
| # Empty stdin when writing to multiple files and its sanitization. |
There was a problem hiding this comment.
| # Empty stdin when writing to multiple files and its sanitization. | |
| # Empty stdout when writing to multiple files and its sanitization. |
Changes
Add tests for safe terminal utilities.
Mandatory Checklist
Terms of Service, Privacy Policy, Cookie Policy, E-Sign Consent, DMCA, Imprint
Optional Checklist
The following items are optional but might be requested in certain cases.
Fixes: